<?php
/**
 * @Author: xuzhiyi
 * @Date:   2016-02-04 15:19:05
 * @Last Modified by:   xuzhiyi
 * @Last Modified time: 2016-02-27 11:47:23
 * ------------------------------------------------ *
 * 权限类                                           *
 * ------------------------------------------------ */
 
 namespace Admin\Controller;

 class AuthsController extends CommonController {

 	public function index(){
 		if(IS_AJAX){
 			switch(I('ajax')){
 				case "authFlag":
					$status = D('auths')->editStatus();
					//dump($status);
					$this->ajaxReturn($status);
					break;
				case 'getParent':
					$a=M('auths');
			 		$parentId = $a->field('authId,authName')->where('parentId=0')->select();
			 		//dump($parentId);exit;
			 		$this->ajaxReturn($parentId);
					break;
				case "addAuths":
					$a = D('auths')->addAuths();
					if($a){
						$this->success('权限添加成功！','',true);	
					}
					$this->error('权限添加失败！','',true);
					break;
				case "delAuths":
					$status = D('auths')->delAuths();
					$this->ajaxReturn($status);
					break;
				case "editAuths":
					$a = D('auths')->editAuths();
					if($a){
						$this->success('权限修改成功！','',true);	
					}
					$this->error('权限修改失败！','',true);
					break;
 				default:
 					$a=M('auths');
			 		$auths = $a->field('*,concat(authPath,authId) as bPath')
			 			->order('concat(authPath,authId)')
			 			->where('authFlag!=-1')
			 			->select();
					$result = array();
			 		foreach($auths as $val){
			 			$val['ac']='';
			 			$result[]=$val;
			 		}
			 		$output['data'] = $result;
			 		$this->ajaxReturn($output);

 			}
 		}
 		
 		$this->display();
 	}

 	
 }

